package com.example.lib;

import java.io.InputStream;

import android.app.ProgressDialog;
import android.content.Context;

import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;

public class AsynDecompress extends AsyncTask<Void, Void, String> {

	private ProgressDialog progressDialog;
	private Context context;
	String zipFile;
	String location;
	private Handler handler;

	public AsynDecompress(String zipFile, String location, Context context,
			Handler handler) {
		super();
		this.handler = handler;
		this.zipFile = zipFile;
		this.context = context;
		this.location = location;
	}

	@Override
	protected void onPreExecute() {
		progressDialog = new ProgressDialog(context);
		progressDialog.setCanceledOnTouchOutside(false);
		progressDialog.setTitle("Waiting");
		progressDialog.show();

		super.onPreExecute();
	}

	@Override
	protected String doInBackground(Void... params) {
		// TODO Auto-generated method stub
		Decompress de = new Decompress(zipFile, location, context);

		return de.unzip();
	}

	@Override
	protected void onPostExecute(String result) {
		Message message = new Message();
		message.what = 1;
		Bundle bundle = new Bundle();

		bundle.putString("link", result);
		message.setData(bundle);

		handler.sendMessage(message);
		progressDialog.dismiss();
		super.onPostExecute(result);
	}

}
